<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试 /api/excel/downloads 接口</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            background: #f5f5f5;
        }
        .container {
            background: white;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input, select {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 5px;
            font-size: 14px;
        }
        button {
            background: #007bff;
            color: white;
            border: none;
            padding: 12px 20px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
        }
        button:hover {
            background: #0056b3;
        }
        .result {
            margin-top: 20px;
            padding: 15px;
            background: #f8f9fa;
            border-radius: 5px;
            border-left: 4px solid #007bff;
            white-space: pre-wrap;
            font-family: monospace;
        }
        .success {
            border-left-color: #28a745;
            background: #d4edda;
        }
        .error {
            border-left-color: #dc3545;
            background: #f8d7da;
        }

        /* 导航栏样式 */
        .navbar {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            padding: 15px 30px;
            border-radius: 15px;
            margin-bottom: 20px;
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
        }

        .nav-brand {
            font-size: 1.2rem;
            font-weight: 600;
            color: #333;
        }

        .nav-links {
            display: flex;
            gap: 20px;
        }

        .nav-link {
            text-decoration: none;
            color: #666;
            padding: 8px 16px;
            border-radius: 8px;
            transition: all 0.3s ease;
            font-weight: 500;
        }

        .nav-link:hover {
            background: #007bff;
            color: white;
            transform: translateY(-2px);
        }

        .nav-link.active {
            background: #007bff;
            color: white;
        }

        @media (max-width: 768px) {
            .navbar {
                flex-direction: column;
                gap: 15px;
                padding: 20px;
            }
            
            .nav-links {
                flex-wrap: wrap;
                justify-content: center;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <!-- 导航栏 -->
        <nav class="navbar">
            <div class="nav-brand">SpringBoot Excel Demo</div>
            <div class="nav-links">
                <a href="/" class="nav-link">🏠 主页面</a>
                <a href="/test_downloads.html" class="nav-link active">📤 异步导出测试</a>
                <a href="/test_image.html" class="nav-link">🖼️ 图片压缩测试</a>
                <a href="/test_easyexcel_import.html" class="nav-link">EasyExcel图片导入测试</a>
            </div>
        </nav>

        <h1>测试 /api/excel/downloads 接口</h1>
        <p>这个页面用于测试异步导出下载功能</p>

        <div class="form-group">
            <label for="downloadId">序号</label>
            <input type="text" id="downloadId" placeholder="请输入序号（可选）">
        </div>

        <div class="form-group">
            <label for="downloadName">姓名</label>
            <input type="text" id="downloadName" placeholder="请输入姓名（可选）">
        </div>

        <div class="form-group">
            <label for="downloadAge">年龄</label>
            <input type="number" id="downloadAge" placeholder="请输入年龄（可选）">
        </div>

        <div class="form-group">
            <label for="downloadGender">性别</label>
            <select id="downloadGender">
                <option value="">请选择性别（可选）</option>
                <option value="1">男</option>
                <option value="2">女</option>
            </select>
        </div>

        <button onclick="testDownloads()">测试异步导出下载</button>

        <div id="result" class="result" style="display: none;"></div>
    </div>

    <script>
        async function testDownloads() {
            const resultDiv = document.getElementById('result');
            resultDiv.style.display = 'block';
            resultDiv.className = 'result';
            resultDiv.textContent = '正在测试...';

            const id = document.getElementById('downloadId').value;
            const name = document.getElementById('downloadName').value;
            const age = document.getElementById('downloadAge').value;
            const gender = document.getElementById('downloadGender').value;

            const downloadData = {
                id: id || null,
                name: name || null,
                age: age ? parseInt(age) : null,
                gender: gender ? parseInt(gender) : null
            };

            try {
                console.log('发送数据:', downloadData);

                const response = await fetch('/api/excel/downloads', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify(downloadData)
                });

                console.log('响应状态:', response.status);

                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }

                const result = await response.json();
                console.log('响应数据:', result);

                resultDiv.className = 'result success';
                resultDiv.textContent = `✅ 请求成功!\n\n状态码: ${response.status}\n响应数据:\n${JSON.stringify(result, null, 2)}`;

            } catch (error) {
                console.error('请求失败:', error);
                resultDiv.className = 'result error';
                resultDiv.textContent = `❌ 请求失败!\n\n错误信息: ${error.message}\n\n请确保:\n1. 应用已启动 (http://localhost:8060)\n2. 接口路径正确 (/api/excel/downloads)\n3. 网络连接正常`;
            }
        }
    </script>
</body>
</html>
